home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12898 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  47 lines

  1. Path: news.vub.ac.be!rc4!apardon
  2. From: apardon@rc1.vub.ac.be (Antoon Pardon)
  3. Newsgroups: comp.lang.c++
  4. Subject: Dynamically initializing static members
  5. Date: 22 Mar 1996 10:11:18 GMT
  6. Organization: Brussels Free Universities (VUB/ULB), Belgium
  7. Message-ID: <4ituc6$c1h@rc1.vub.ac.be>
  8. NNTP-Posting-Host: mailhost.vub.ac.be
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. I am playing with the idea of somekind of classregistration.
  12.  
  13. The registration class would provide for a function: 
  14.  
  15. unsigned int Registrate(const char *name);
  16.  
  17. This would keep the name of the function stored somewhere and
  18. would return a registration ID.
  19.  
  20. The idea would be to include a static int into the class that
  21. would store this ID something like this
  22.  
  23. class MYCLASS {
  24.   static unsigned int
  25.     Registration_ID
  26.  
  27.   ...
  28.  
  29. }
  30.  
  31. The problem now is how do I assign this Registration_ID
  32. automatically. In Modula 2 you have initialisation code
  33. that is called at the start of the program where you might
  34. then put code similar to 
  35.  
  36. MYCLASS::Registration_D = Registrate("MYCLASS");
  37.  
  38. Is something similar possible in C++ or do I have to
  39. do it in a different way? I looked at the FAQ but
  40. couldn't find an answer there.
  41.  
  42. --
  43. All opinions expressed herein are currently under revision
  44. ==========================================================
  45. Antoon Pardon    Brussels Free University Computing Centre
  46. ==========================================================
  47.